import 'package:fusion_one/dtos/file.dart';
import 'package:fusion_one/dtos/patientList.dart';
import 'package:fusion_one/dtos/stage.dart';
import 'package:fusion_one/http/request.dart';

class Api {
  static DioUtils dio = DioUtils();
  // 根据患者id获取治疗阶段列表
  static Future<List<Stage>> getStageListByPid(String pid) async {
    var url = '/api/StageService/GetStageListByPid/$pid';
    var response = await dio.get(url);
    return (response.resultInfo as List<dynamic>)
        .map((e) => Stage.fromJson(e))
        .toList();
  }

  // 查询患者列表
  static Future<List<Patient>> queryPatientList() async {
    var patientResult = await dio.get('/api/PatientService/QueryPatientList',
        params: {"pageNum": 1, "rowNum": 20});
    return (patientResult.resultInfo['resultData'] as List<dynamic>)
        .map((e) => Patient.fromJson(e))
        .toList();
  }

  // 查询治疗阶段文件列表
  static Future<List<File>> queryStageFileList(
      {required String stageId, String? pid}) async {
    var url = '/api/StageService/QueryFilesInfo/$stageId';
    var response = await dio.get(url, params: pid != null ? {"pid": pid} : {});
    return (response.resultInfo as List<dynamic>)
        .map((e) => File.fromJson(e))
        .toList();
  }
}
